using System;
using NguyenHoa.Web.App_Code;

namespace NguyenHoa.Web.Controls
{
  public partial class FunctionDivide : AdminBaseControl
  {
    #region Properties

    public int FunctionObjId
    {
      get
      {
        int funtcionId = -1;
        int.TryParse(hfFunctionObjId.Value, out funtcionId);
        return funtcionId;
      }
      set
      {
        hfFunctionObjId.Value = value.ToString();
      }
    }
    public string FunctionObj
    {
      get
      {
        return lblPageName.Text;
      }
      set
      {
        lblPageName.Text = value;
      }
    }
    public int Actions
    {
      get
      {
        int result = 0;
        if (cbView.Checked)
        {
          result = result | PermissionValue.View;
        }
        if (cbModify.Checked)
        {
          result = result | PermissionValue.Modify;
        }
        if (cbDelete.Checked)
        {
          result = result | PermissionValue.Delete;
        }
        if (cbApprove.Checked)
        {
          result = result | PermissionValue.Approve;
        }
        return result;
      }
      set
      {
        cbView.Checked = (value & PermissionValue.View) != 0;
        cbModify.Checked = (value & PermissionValue.Modify) != 0;
        cbDelete.Checked = (value & PermissionValue.Delete) != 0;
        cbApprove.Checked = (value & PermissionValue.Approve) != 0;
      }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack) return;
      cbApprove.Attributes.Add("onclick", String.Format("checkCheckBox('{0}', '{1}');", cbView.ClientID, cbApprove.ClientID));
      cbModify.Attributes.Add("onclick", String.Format("checkCheckBox('{0}', '{1}');", cbView.ClientID, cbModify.ClientID));
      cbDelete.Attributes.Add("onclick", String.Format("checkCheckBox('{0}', '{1}');", cbView.ClientID, cbDelete.ClientID));
      cbView.Attributes.Add("onclick", String.Format("checkView('{0}', '{1}', '{2}', '{3}');", cbView.ClientID, cbDelete.ClientID, cbModify.ClientID, cbApprove.ClientID));
    }
  }
}